package ups.Schedule;

public class ScheduleTime {
	private int mHour;
	private int mMinute;
	/* Assumes 24 Hour Time */
	public ScheduleTime( int hours, int minutes ) {
		initialize( hours, minutes );
	}
	public ScheduleTime( int hours, int minutes, boolean am ) {
		if( !am ) {
			initialize( hours + 12, minutes );
		} else {
			initialize( hours, minutes );
		}
	}
	
	public ScheduleTime( String stringRepresentation, boolean am ) {
		String[] parts = stringRepresentation.split(":");
		Integer hourPart = new Integer( parts[0] );
		Integer minutePart = new Integer( parts[1] );
		if( am ) {
			if( hourPart == 12 ) {
				hourPart = 0;
			}
			initialize( hourPart, minutePart );
		} else {
			if( hourPart == 12 ) {
				hourPart = 0;
			}
			initialize( 12 + hourPart, minutePart );
		}
	}
	
	/* Assumes 24 Hour Time */
	public void initialize( int hours, int minutes ) {
		if( hours > 24 ) {
			System.err.println("ERROR: Time initialized with hour > 24");
		}
		if( minutes > 60 ) {
			System.err.println("ERROR: Time initialized with mintues > 60 ");
		}
		
		mHour = hours;
		mMinute = minutes;
	}
	
	public void setHours( int hours ) {
		mHour = hours;
	}
	
	public int getHours() {
		return mHour;
	}
	
	public int getMinutes() {
		return mMinute;
	}
	
	public String toString() {
		String minuteString;
		String hourString;
		if( mHour < 10 ) {
			hourString = "0" + mHour;
		} else {
			hourString = "" + mHour;
		}
		if( mMinute < 10 ) {
			minuteString = "0" + mMinute;
		} else {
			minuteString = "" + mMinute;
		}
		return hourString + ":" + minuteString;
	}
}
